<template>
    <div class="main">
        <div class="container">
            <div class="box">
                <div class="item">
                    <div v-html="compiledMarkdown" class="markdown-body" style="font-size: large"></div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>
.item {
    /* margin-left: 10%; */
}

/* 媒体查询(手机端) */
@media (max-width: 768px) {
    .markdown-body {
        padding: 15px;
    }
}

/* 媒体查询（电脑端） */
@media (min-width: 769px) {
    .item {
        padding: 1rem;
    }
}

/* 以下是markdown的 */

.markdown-body {
    box-sizing: border-box;
    min-width: 200px;
    max-width: 980px;
    margin: 0 auto;
    padding: 45px;
}
</style>



<script setup lang="ts">
import { ref, computed } from 'vue';
import MarkdownIt from 'markdown-it';
import { useRoute } from 'vue-router';
import { onMounted } from 'vue';
import { getOneArticle } from '../utils/axios';
const route = useRoute();
const markdown = ref('');

onMounted(() => {
    const { query } = route;
    // console.log(query.id);
    getOneArticle(query.id).then(success=>{
        console.log(success.data.data.data);
        markdown.value = success.data.data.data.content
    }).catch(()=>{

    })

})


const markdownIt = new MarkdownIt({
    html: true,
    linkify: true,
    typographer: true,
});
// 使用computed创建计算属性
const compiledMarkdown = computed(() => markdownIt.render(markdown.value));


</script>
